package cn.edu.scau.cmi.linyiqu.abstractFactory;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.linyiqu.abstractFactory.domainAbstractClass.Meat;
import cn.edu.scau.cmi.linyiqu.abstractFactory.factory.AbstractFactory;
import cn.edu.scau.cmi.linyiqu.abstractFactory.factory.AonongFactory;
import cn.edu.scau.cmi.linyiqu.abstractFactory.factory.TianbangFactory;
import cn.edu.scau.cmi.linyiqu.abstractFactory.factory.WensFactory;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;

public class Controller implements Initializable {

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
	}

	@FXML
	private TextArea output;

	@FXML
	private TextField brandInput;

	@FXML
	private Button produceButton;

	@FXML
	private TextField meatInput;


	@FXML
	void produce(MouseEvent event) {
		String brandString = brandInput.getText();
		String meatString = meatInput.getText();
		AbstractFactory factory = null;
		Meat meat = null;
		switch (brandString) {
		case "Tianbang":
			factory = new TianbangFactory();
			break;
		case "Wens":
			factory = new WensFactory();
			break;
		case "Aonong":
			factory = new AonongFactory();
			break;
		}

		if(factory!=null)
		switch (meatString) {
		case "beef":
			meat = factory.createBeef();
			break;
		case "chicken":
			meat = factory.createChicken();
			break;
		case "pork":
			meat = factory.createPork();
			break;
		}

		if(meat!=null) {
			output.appendText(meat.product()+"\n");
		}else output.appendText("Input Error!!!\n");
	}

}
